<script>
	export default {
		onLaunch: function() {
			//启动授权获取位置、摄像头功能
			uni.getSetting({
				success(res) {
					if(res.authSetting['scope.userLocation'] === undefined){
						uni.authorize({
							scope: 'scope.userLocation',
							success() {}
						})
					}
					if(res.authSetting['scope.camera'] === undefined){
						uni.authorize({
							scope: 'scope.camera',
							success() {}
						})
					}
				}
			})
			console.log('App Launch')
		},
		onShow: function() {
			//获取已保存在本地的用户信息，该内容在登录页面登录成功之后，才保存到本地的
			const userLoginInfo = uni.getStorageSync('user_info');
			const recognizeStatus = uni.getStorageSync('recognizeStatus');
			if (userLoginInfo) {
				this.$u.api.mine.userinfo({}).then((res) => {
					if(res.code === 0 && res.data.recognizeStatus !== recognizeStatus){
						//清空存储信息
						uni.clearStorageSync('token')
						uni.clearStorageSync('user_info')
						uni.clearStorageSync('recognizeStatus')
						uni.navigateTo({
							url: '/pages/sys/login/index'
						})
					}
				}).catch(e => {
					if(e.data.msg === '请先登录'){
						//清空存储信息
						uni.clearStorageSync('token')
						uni.clearStorageSync('user_info')
						uni.clearStorageSync('recognizeStatus')
						uni.navigateTo({
							url: '/pages/sys/login/index'
						})
					}
				}); 
			} else {
				// plus.navigator.closeSplashscreen(); //关闭启动页，进入首页
			}
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
</style>
